#include <jni.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <vector>
#include <jni.h>
#include <string.h>

using namespace std;
using namespace cv;

extern "C" {
JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial3_Sample3Native_FindFeatures(JNIEnv*, jobject, jlong addrGray, jlong addrRgba);
JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial3_Sample3Native_TextOut(JNIEnv*, jobject, jlong addrRgba);

JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial3_Sample3Native_FindFeatures(JNIEnv*, jobject, jlong addrGray, jlong addrRgba)
{
	Mat& mGr  = *(Mat*)addrGray;
	Mat& mRgb = *(Mat*)addrRgba;
	vector<KeyPoint> v;

	FastFeatureDetector detector(50); // the features of 10 circles with name
	detector.detect(mGr, v);
	for( unsigned int i = 0; i < v.size(); i++ )
	{
		const KeyPoint& kp = v[i];
		//circle(mRgb, Point(kp.pt.x, kp.pt.y), 10, Scalar(255,0,0,255));
		circle(mRgb, Point(kp.pt.x, kp.pt.y), 15, Scalar(0,255,0,255));

	}
}

JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial3_Sample3Native_TextOut(JNIEnv*, jobject, jlong addrRgba)
{

	Mat& mRgb = *(Mat*)addrRgba;

	putText(mRgb, "Hello from JNI!", Point(30,30),
	    FONT_HERSHEY_COMPLEX_SMALL, 2.0, Scalar(0,255,0,250));

}


}


